import JSONP from 'jsonp'

function param(data) {
  let url='';
  for (var k in data){
    let v=data[k]!==undefined?data[k]:''
    url+=`${k}=${encodeURIComponent(v)}`
  }
  return url
}

export default function jsonp(url,data,option) {
  url+=(url.indexOf('?')<0 ? '?':'&')+param(data)
  return new Promise((resolve,reject)=>{
    JSONP(url,option,(err,data)=>{
      if(!err){
        resolve(data)
      }else{
        reject(err)
      }
  })
  })
}
